package goleetcode

import "math"

func giveGem(gem []int, operations [][]int) int {
	numMax := func(nums []int) int {
		max_ := math.MinInt
		for _, num := range nums {
			max_ = max(max_, num)
		}
		return max_
	}

	numMin := func(nums []int) int {
		min_ := math.MaxInt
		for _, num := range nums {
			min_ = min(min_, num)
		}
		return min_
	}

	for _, operation := range operations {
		x ,y := operation[0], operation[1]
		genSend := gem[x] / 2
		gem[x] -= genSend
		gem[y] += genSend
	}

	return numMax(gem) - numMin(gem)
}